﻿using System;
using System.Collections.Generic;
using System.Text;

namespace NetstsadmService
{
    /// <summary>
    /// Mecanism, like a pattern so that the service can interact with the UI. The MainForm will implement the ILogger interface so that
    /// the textarea can receive text
    /// </summary>
    internal class Logger
    {
        static Logger instance = null;
        static readonly object padlock = new object();

        ILogger logger;

        static internal Logger GetLogger()
        {
            lock (padlock)
            {
                if (instance == null)
                {
                    instance = new Logger();
                }
                return instance;
            }
        }

        internal ILogger LoggerComponent
        {
            get { return logger; }
            set { logger = value; }
        }

        internal void Notify(string Text)
        {
            if (LoggerComponent == null)
                throw new InvalidOperationException("You have to specify a logger first");

            LoggerComponent.Write(Text);
        }
    }
}
